package com.njuse.jvmfinal.memory.jclass.runtimeConstantPool.constant.ref;

import com.njuse.jvmfinal.classloader.classfileparser.constantpool.info.InterfaceMethodrefInfo;
import com.njuse.jvmfinal.memory.jclass.Field;
import com.njuse.jvmfinal.memory.jclass.JClass;
import com.njuse.jvmfinal.memory.jclass.Method;
import com.njuse.jvmfinal.memory.jclass.runtimeConstantPool.RuntimeConstantPool;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class InterfaceMethodRef extends MemberRef {
    private Method method;

    public InterfaceMethodRef(RuntimeConstantPool runtimeConstantPool, InterfaceMethodrefInfo interfaceMethodrefInfo) {
        super(runtimeConstantPool, interfaceMethodrefInfo);
        //method
    }
    
    public Method findmethod() {
    	return findmethod(findclass());
    }
    
    public Method findmethod(JClass clazz) {
    	Method[] methods=clazz.getMethods();
    	for (int i=0;i<methods.length;i++) {
    		if (methods[i].getDescriptor().equals(descriptor)&&methods[i].getName().equals(name)) {
    			return methods[i];
    		}
    	}

        JClass[] interfaces=clazz.getInterfaces();
        for (int i=0;i<interfaces.length;i++) {
            Method temp =findmethod(interfaces[i]);
            if (temp!= null) return temp;
        } 
    	return null;
    }
}
